﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogicUniversityBiz
{
    public class ReorderReportControl
    {
        private DateTime firstDay;
        private DateTime endDay;

        private LogicUniversityEntities contextDB = new LogicUniversityEntities();
        public void getFirstDayOf(DateTime date)
        {
           firstDay = new DateTime(date.Year, date.Month, 1);
            
        }
        public void getEndDayOf(DateTime date)
        {
            endDay = new DateTime(date.Year,date.Month, DateTime.DaysInMonth(date.Year, date.Month));
            
        }

        public IQueryable getPurchaseOrderBy(DateTime date)
        {
            getFirstDayOf(date);
            getEndDayOf(date);

            var query = from po in contextDB.Purchse_Order
                        join pd in contextDB.Purchase_Order_Detail
                        on po.PO_No equals pd.PO_No
                        join c in contextDB.Catelogues
                        on pd.Item_Code equals c.Item_Code
                        where (po.Order_Datee >= firstDay && po.Order_Datee <= endDay)
                        select new
                        {
                            pd.Item_Code,
                            c.Item_Description,
                            pd.OnHand_Quantity,
                            c.Reorder_Level,
                            c.Reorder_Qty,
                            pd.PO_No,
                            po.Expected_Deliver_Date
                        };

            return query;
        }
    }
}
